﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace ServerMonitor
{
    public class DeviceListSection : ConfigurationSection
    {
        public override bool IsReadOnly()
        {
            return true;
        }

        [ConfigurationProperty("deviceList", IsDefaultCollection = false)]
        [ConfigurationCollection(typeof(DeviceSection), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap, RemoveItemName = "remove")]
        public DeviceSectionContainer DeviceSectionContainer
        {
            get
            {
                return (DeviceSectionContainer)base["deviceList"];
            }
        }
    }

    public class DeviceSectionContainer : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new DeviceSection();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((DeviceSection)element).DeviceName;
        }

        public DeviceSection this[int i]
        {
            get
            {
                return (DeviceSection)base.BaseGet(i);
            }
        }

        public DeviceSection this[string key]
        {
            get
            {
                return (DeviceSection)base.BaseGet(key);
            }
        }
    }

    public class DeviceSection : ConfigurationElement
    {
        public override bool IsReadOnly()
        {
            return true;
        }

        [ConfigurationProperty("deviceName", IsRequired = true)]
        public string DeviceName
        {
            get { return this["deviceName"] as string; }
        }

        [ConfigurationProperty("ipAddress", IsRequired = true)]
        public string IpAddress
        {
            get { return this["ipAddress"] as string; }
        }


        [ConfigurationProperty("password", IsRequired = true, DefaultValue = "cios")]
        public string Password
        {
            get { return this["password"] as string; }
        }

        [ConfigurationProperty("userName", IsRequired = true, DefaultValue = "administrator")]
        //[IntegerValidator(MaxValue = 65535, MinValue = 1)]
        public string UserName
        {
            get { return this["userName"] as string; ; }
        }
    }
}
